import request from "./request/request";
import {IComponent} from "@bastet/widgets";

export interface IMaterial {
    id?: string
    name: string
    description?: string
    widgets?: IComponent[];
}
interface IMaterialResponse {
    data: IMaterial[]
    code: number;
}

// 新增
export function addMaterial (data: IMaterial): Promise<IMaterialResponse> {
    return request.post('/material', data)
}

// 列表
export function getMaterials (): Promise<IMaterialResponse> {
    return request.get('/material/list')
}

// 更新
export function updateMaterial (data: IMaterial) {
    return request.put(`/material/${data.id}`, data)
}

// 详情
export function getMaterial (id: string) {
    return request.get(`/material/${id}`)
}

// 删除
export function removeMaterial (id: string) {
    return request.delete(`/material/${id}`)
}